{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Find Pythagorean Triplets\n",
    "\n",
    "[The Orignal Question](https://mp.weixin.qq.com/s/gKHMgxLFR3rjs5bjY9HwYw)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question\n",
    "\n",
    "Given a list of numbers, find if there exists a pythagorean triplet in that list. A pythagorean triplet is 3 variables `(a, b, c)` where `a^2 + b^2 = c^2`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example\n",
    "\n",
    "```text\n",
    "Input: [3, 5, 12, 5, 13]\n",
    "Output: True\n",
    "```\n",
    "\n",
    "$$\n",
    "5^2 + 12^2 = 13^2\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def exist_pythagorean(array: list) -> bool:\n",
    "    array.sort()\n",
    "    for i in range(len(array) - 1):\n",
    "        for j in range(1, len(array)):\n",
    "            if math.sqrt(array[i] ** 2 + array[j] ** 2) in array:\n",
    "                return True\n",
    "            pass\n",
    "        pass\n",
    "    return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(exist_pythagorean([3, 5, 12, 5, 13]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
